home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / intrvews / xgrab.lha / xgrab / ui / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-03-07  |  4.6 KB  |  244 lines

  1. /**
  2.    GRAB Graph Layout and Browser System
  3.  
  4.    Copyright (c) 1986, 1988 Regents of the University of California
  5.    Copyright (c) 1989, Tera Computer Company
  6.  **/
  7.  
  8.   /**
  9.     New and improved xgrab program. Now better than ever...
  10.    **/
  11.  
  12. #include "malloc.h"
  13. #include <stdio.h>
  14. #include <strings.h>
  15.  
  16. #include "attribute.h"
  17. #include "digraph.h"
  18. #include "globals.h"
  19. #include "checkpoint.h"
  20. #include "interf.h"
  21.  
  22. #define DEFAULT_NAME    ""
  23.  
  24. extern void gmain();
  25. extern VNO get_vno();
  26.  
  27. extern double atof();
  28. extern int atoi();
  29. extern BOOL ReadIn();
  30.  
  31. char cfileName[MAXSTR];
  32. BOOL cfile;
  33.  
  34.   /**
  35.      main --
  36.      process any options. Set up the window program.
  37.      After things are set up we go into a select loop processing input
  38.      from the mouse and keyboard.
  39.    **/
  40. main(argc,argv)
  41. int argc;
  42. char *argv[];
  43. {
  44.       /* initialize command line argument flag variables */
  45.     InitCommandLineArgFlags();
  46.       /* process the command line arguments */
  47.     ProcessArgs(argc, argv);
  48.     ginit(argc, argv);
  49.       /* initialize global variables */
  50.     InitGlobals();
  51.       /* now make sure the asterisks are on the ON toggle menu items */
  52.     AsteriskOnToggles();
  53.  
  54.       /* read in the graph and print it on the screen */
  55.     if (ReadIn())
  56.     {
  57.         if (cfile)
  58.           /* execute some commands initially */
  59.         {
  60.         read_commands(cfileName, TRUE);
  61.         }
  62.     else
  63.     {
  64.         DisplayReadGraph();
  65.     }
  66.     }
  67.     else
  68.     {
  69.     DisplayReadGraph();
  70.     }
  71.  
  72.       /* call the top level routine.  */
  73.     grun();
  74.     exit(0);    
  75. }
  76.  
  77. InitCommandLineArgFlags()
  78. {
  79.     int i;
  80.  
  81.     aspratio = 1.5;
  82.     printLayoutTime = FALSE;
  83.     stopInLayout = DONT_STOP;
  84.     debug = FALSE;
  85.     debug1 = FALSE;
  86.     debug2 = FALSE;
  87.     debug3 = FALSE;
  88.     showbc = FALSE;
  89.     cfile = FALSE;
  90.     name = (char *) malloc(MAXSTR * (sizeof(char)));
  91.     strcpy(name, DEFAULT_NAME);
  92.  
  93.     immedPercent = 1.0;
  94.     for (i = 0; i < MAX_HEURISTIC; i++)
  95.     heuristic[i] = FALSE;
  96. }
  97.  
  98. #define ARGVAL() (*++(*argv) || (--argc && *++argv))
  99.  
  100. ProcessArgs(argc, argv)
  101. int argc;
  102. char *argv[];
  103. {
  104.     int readfile = 0;
  105.  
  106.       /* Argument Processing */
  107.     for (argc--, argv++; argc > 0; argc--, argv++) 
  108.     {
  109.     if (**argv == '-')             /* A flag argument */
  110.     {    
  111.         while (*++(*argv))         /* Process all flags in this arg */
  112.         {    
  113.         switch (**argv) 
  114.         {
  115.             case 'd':
  116.             if (ARGVAL()) 
  117.             {
  118.                 switch(atoi(*argv)) 
  119.                 {
  120.                 case 0:
  121.                     debug = TRUE;
  122.                     break;
  123.                 case 1:
  124.                     debug1 = TRUE;
  125.                     break;
  126.                 case 2:
  127.                     debug2 = TRUE;
  128.                     break;
  129.                 case 3:
  130.                     debug3 = TRUE;
  131.                     break;
  132.                 default:
  133.                     break;
  134.                 };
  135.  
  136.                 goto nextarg;
  137.             }
  138.             break;
  139.             case 's': 
  140.             showbc = TRUE;
  141.             break;
  142.             case 't':
  143.             printLayoutTime = TRUE;
  144.             break;
  145.             case 'l':
  146.             if (ARGVAL()) 
  147.             {
  148.                 switch (atoi(*argv)) 
  149.                 {
  150.                 case 1:
  151.                     stopInLayout = STOP_AFTER_MAKEPROPER;
  152.                     break;
  153.                 case 2:
  154.                     stopInLayout = STOP_AFTER_MIN_CROSSING;
  155.                     break;
  156.                 default:
  157.                     break;
  158.                 }
  159.  
  160.                 goto nextarg;
  161.             }
  162.             break;
  163.             case 'a':
  164.             if (ARGVAL()) 
  165.             {
  166.                 aspratio = atof(*argv);
  167.                 goto nextarg;
  168.             }
  169.             break;
  170.             case 'b':
  171.             if (ARGVAL()) 
  172.             {
  173.                 immedPercent = atof(*argv);
  174.                 goto nextarg;
  175.             }
  176.             break;
  177.             case 'h':
  178.             if (ARGVAL()) 
  179.             {
  180.                 heuristic[atoi(*argv)] = TRUE;
  181.             }
  182.             break;
  183.             case 'C':
  184.             if (ARGVAL())
  185.             {
  186.                 strncpy(cfileName, *argv, MAXSTR - 1);
  187.                 cfile = TRUE;
  188.                 goto nextarg;
  189.             }
  190.             break;
  191.             default:
  192.             fprintf(stderr, "Unknown flag: '%c';\n", **argv);
  193.             fprintf(stderr, "Usage: xgrab [-a aspectRatio] [-C commandFileName] [-t] [-l1] [-l2] [-dn] [-s] [-b BC-Percentage] [-hn] [filename]\n");
  194.             exit(1);
  195.         }
  196.         }
  197.     }
  198.     else         /* Input file name */
  199.     {              
  200.         if (readfile == 0) 
  201.         {
  202.         strncpy(name, *argv, MAXSTR - 1);
  203.         readfile++;
  204.         }
  205.         else 
  206.         {
  207.         fprintf(stderr,
  208.             "Duplicate input filenames: keeping %s, ignoring %s\n",
  209.             name, *argv);
  210.         }
  211.     }
  212.  
  213.     nextarg: continue;
  214.     }
  215. }
  216.  
  217.   /**
  218.      InitGlobals --
  219.      Inititalize all the global variables that need initializing.
  220.    **/
  221. InitGlobals()
  222. {
  223.     currMode          = IN_BROWSE_MODE;
  224.     zoomGradient     = 0.75;
  225.     panGradient     = 0.05;
  226.     Text_Flag         = TRUE;
  227.     printArrow         = TRUE;
  228.     printEdgeLabel     = FALSE;
  229.     inChangeTextMode     = FALSE;
  230.     inChangeEdgeLabelMode = FALSE;
  231.     printNodeLabel     = FALSE;
  232.     markDummyNodes     = FALSE;
  233.     graphChanged     = FALSE;
  234.     ckpt_done         = TRUE;
  235.     changeOutEdges     = FALSE;
  236.     changeInEdges     = FALSE;
  237.     landscapePSFile     = FALSE;
  238.     straightenEdges    = FALSE;
  239.     ignoreHidden    = TRUE;
  240.     num_ckpts        = 0;
  241.     curr_ckpt        = -1;
  242.     ckpts        = NULL;
  243. }
  244.